<template>
	<view class="goods-exchange" v-if="promotion">
        <view class="prom-bar-container">
            <view class="u-flex">
                <custom-price :price="promotion.exchange_money" :size="50" :textColor="'#FFFFFF'"></custom-price>
                <view class="u-m-l-10 u-m-t-20">
                    + {{ promotion.exchange_point }} 积分
                </view>
            </view>
            <view class="msg">
                <view class="text">
                  <text class="old-price">{{ promotion.goods_price | unitPrice('￥') }}</text>
                </view>
                <view class="text">
                  <text class="icon exchange">积分兑换</text>
                </view>
            </view>
        </view>
	</view>
</template>

<script>
    /**
     * 商品详情页积分兑换组件
     *
     * ===== 使用场景 ======
     * 商品详情页。
     *
     * ===== 参数 =====
     * promotions      促销活动
     */
	export default {
        props: {
            promotions: {
                type: Array,
                default() {
                    return []
                }
            }
        },
        computed: {
            promotion() {
                const { promotions } = this
                if (!promotions || !promotions.length) return false
                let prom = promotions.filter(item => item.exchange)
                if (prom[0]) return prom[0].exchange
                return false
            }
        }
	}
</script>

<style lang="scss" scoped>
    .prom-bar-container {
        position: relative;
        display: flex;
        align-items: center;
        z-index: 10;
        height: 49px;
        color: #fff;
        background: url(../../static/images/background-promotion-bar.png) no-repeat,-webkit-linear-gradient(top,#fc5997,#ef4747);
        background-size: 259px,100%;
        .msg {
          flex: 1;
          font-size: 12px;
          margin-left: 20rpx;
          .old-price {
              text-decoration: line-through;
          }
          .icon {
            position: relative;
            display: inline-block;
            margin: -2px 3px 0 0;
            padding: 0 3px 0 18px;
            height: 15px;
            vertical-align: middle;
            line-height: 15px;
            font-size: 10px;
            &.exchange::before {
              background: #fff url() no-repeat 50%;
              background-size: 12px
            }
            &::before {
              content: "";
              position: absolute;
              left: 0;
              top: 0;
              width: 15px;
              height: 15px;
              border-top-left-radius: 1px;
              border-bottom-left-radius: 1px;
            }
            &::after {
              content: "";
              display: block;
              border: 1px solid #fff;
              position: absolute;
              top: 0;
              left: 0;
              pointer-events: none;
              bottom: 0;
              right: 0;
              border-radius: 2px;
            }
          }
        }
      }
</style>
